package com.imti.mall.sale.mapper;

import com.imti.mall.model.sms.pojo.SmsHomeNewProduct;
import com.imti.mall.model.sms.pojo.SmsHomeRecommendProduct;
import org.apache.ibatis.jdbc.SQL;

public class SmsHomeRecommendProductMapper {

    /**
     * 查询人气推荐商品表
     */
    public String findSmsHomeRecommendProduct(final SmsHomeRecommendProduct smsHomeRecommendProduct){
        return new SQL(){
            {
                SELECT(" id,product_id,product_name,recommend_status,sort ");
                FROM(" sms_home_recommend_product ");
                StringBuffer sb=new StringBuffer();
                if(smsHomeRecommendProduct!=null){

                    if(smsHomeRecommendProduct.getProductId()!=null){
                        sb.append(" and product_id=#{productId} ");
                    }

                    if(smsHomeRecommendProduct.getRecommendStatus()!=null){
                        sb.append(" and recommend_status=#{recommendStatus} ");
                    }

                    if(smsHomeRecommendProduct.getProductName()!=null){
                        sb.append(" and product_name LIKE concat('%',#{productName},'%') ");
                    }

                }
                WHERE(" 1=1 "+sb.toString());
                ORDER_BY(" sort desc ");
            }
        }.toString();
    }


    /**
     * 修改人气推荐商品表
     * @param smsHomeRecommendProduct
     * @return
     */
    public String updateSmsHomeRecommendProduct(final SmsHomeRecommendProduct smsHomeRecommendProduct){
        return new SQL(){
            {
                UPDATE(" sms_home_recommend_product ");
                if(smsHomeRecommendProduct.getProductId()!=null){
                    SET(" product_id=#{productId} ");
                }
                if(smsHomeRecommendProduct.getProductName()!=null){
                    SET(" product_name=#{productName} ");
                }
                if(smsHomeRecommendProduct.getRecommendStatus()!=null){
                    SET(" recommend_status=#{recommendStatus} ");
                }
                if(smsHomeRecommendProduct.getSort()!=null){
                    SET("  sort=#{sort}");
                }

                WHERE(" id=#{id} ");
            }
        }.toString();
    }
}
